Skip to content

fix(console): preserve non-string first arguments - #5688

Open
PeterlitsZo wants to merge 1 commit into
boa-dev:mainfrom
PeterlitsZo:fix/console-non-string-first-argument-5687
Open

PeterlitsZo wants to merge 1 commit into
boa-dev:mainfrom
PeterlitsZo:fix/console-non-string-first-argument-5687

Conversation

@PeterlitsZo

Copy link
Copy Markdown

This Pull Request fixes/closes #5687 .

It changes the following:

  • Only treat string first arguments as format strings and add regression coverage for non-string values.

Only treat string first arguments as format strings and add regression coverage for non-string values.

Fixes boa-dev#5687.
@PeterlitsZo
PeterlitsZo requested a review from a team as a code owner November 24, 2026 09:56
@github-actions github-actions Bot added Waiting On Review Waiting on reviews from the maintainers C-Tests Issues and PRs related to the tests. labels Nov 24, 2026
@github-actions github-actions Bot added this to the v0.23 milestone Nov 24, 2026

@abdulhamid999 abdulhamid999 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed against core/wintertc/src/console/mod.rs and core/wintertc/src/console/tests.rs (static inspection; not compiled locally).

Findings

  • Spec & behavior fix: Switching from data.get_or_undefined(0).to_string(context)? to let Some(target) = data[0].as_string() else { ... } matches the WHATWG Console Formatter behavior when the first argument is not a primitive string. It resolves three issues at once:
    1. Avoids throwing TypeError when logging a Symbol followed by additional arguments.
    2. Avoids invoking custom .toString() on objects/arrays for multi-arg console.log calls (bringing it in line with the single-argument [val] arm).
    3. Prevents % format specifiers inside stringified arrays/objects (such as ['%s']) from consuming subsequent arguments.
  • Consistency & safety: All call sites in core/wintertc/src/console/mod.rs pass slices into formatter, and the else fallback runs after [] and [val], so data.len() >= 2 holds whenever data[0] is indexed. Using to_string(value, context) joined with " " matches the formatting of [val] and trailing unformatted arguments.

Minor Nits / Suggestions

  • Typo in comment (core/wintertc/src/console/mod.rs inside formatter): // Only strings are format strings. Otherwises do not format it. -> Otherwise, do not format it.
  • Boxed String object test (optional): new String('%s') has as_string() == None (so it rightly avoids format substitution); adding a test case like console.log(new String('%s'), 'tail') in console_log_non_string_first_argument would explicitly lock in that edge case as well.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-Tests Issues and PRs related to the tests. Waiting On Review Waiting on reviews from the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

console.log drops the first argument when it is an empty array

2 participants